package nl.hu.modellingengine.client;

import nl.hu.modellingengine.client.place.AppPlaceHistoryMapper;
import nl.hu.modellingengine.client.place.InitPlace;
import nl.hu.modellingengine.grid.client.Grid;
import nl.hu.modellingengine.menu.client.Menu;
import nl.hu.modellingengine.ribbon.client.Ribbon;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Modellingengine implements EntryPoint {
	final private Place defaultPlace = new InitPlace();

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		ClientFactory clientFactory = GWT.create(ClientFactory.class);
		EventBus eventBus = clientFactory.getEventBus();
        PlaceController placeController = clientFactory.getPlaceController();
        
        //load modules {menu,ribbon,grid}
        Menu mnu = new Menu(RootPanel.get("menu"),clientFactory);
        Ribbon rbn = new Ribbon(RootPanel.get("tabbar"),clientFactory);
        Grid grid = new Grid(RootPanel.get(),clientFactory);
        
        // Start PlaceHistoryHandler with our PlaceHistoryMapper
        AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
        PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler.register(placeController, eventBus, defaultPlace);
        
        historyHandler.handleCurrentHistory();
	}
}
